#ifndef CASEDB_IMPL_CONNECTION_IMPL_HPP
#define CASEDB_IMPL_CONNECTION_IMPL_HPP

#include <QtSql/QSqlDatabase>
#include <string>

class QSqlDriver;
class QSqlQuery;

namespace CaseDB { class Statement; class RecordSet; }

namespace CaseDB { namespace Impl
{

/// @ingroup CaseDB
/// @brief It implements a database connection using QT QSql module.
///
/// The current implementation uses the Qt QSql module for database operations.
/// @sa CaseDB::Connection
class ConnectionImpl
{
protected:
	/// @brief It initializes the connection.
	/// @param name the name of the connection to be initialized.
	/// @param type the name of the connection type to be initialized.
	ConnectionImpl( const std::string& name, const std::string& type);

public:
	/// @brief It closes the database connection.
	virtual ~ConnectionImpl();

	/// @brief It opens the connection to the database.
	virtual void open();

	/// @brief It closes the connection to the database.
	virtual void close();

	/// @brief It executes the given statement.
	/// 
	/// After execution, the statement's output parameters will contain the output values.
	void execute( Statement& statement);

	/// @brief It executes the given statement and puts in the specified record set the results of the query.
	/// 
	/// After execution, the statement's output parameters will contain the output values.
	void execute( Statement& statement, RecordSet& results);

protected:
	QSqlDatabase database_;

private:
	/// @brief It executes the given statement and puts the values in the output parameters.
	/// 
	/// This is the statement execution implementation common to queries and DML statements.
	void execute( Statement& statement, QSqlQuery& qSql);
};

} } // namespace Impl // namespace CaseDB

#endif // CASEDB_IMPL_CONNECTION_IMPL_HPP
